﻿using System;
using System.Net;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
namespace Silverlight4Demo.Model {

    [DataContract]
    public class MockListData:INotifyPropertyChanged {
        [DataMember]
        public List<MockSomethingData> DataList {
            get;
            set;
        }

        private string name1;
        private string name2;
          [DataMember]
        public string Name1 {
            get { return name1; }
            set {
                name1 = value;
                FirePropertyChanged("Name1");
            }
        }
          [DataMember]
        public string Name2 {
            get { return name2; }
            set {
                name2 = value;
                FirePropertyChanged("Name2");
            }
        }

       
        private void FirePropertyChanged(string p) {
            if (PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(p));
            }
        }

        public MockListData( ) {
            DataList = new List<MockSomethingData>( );
        }

        public static MockListData Mock(int count ) {
            MockListData dataObj = new MockListData( );
            for (int i = 0; i < count; i++) {
                dataObj.DataList.Add(
                    MockSomethingData.Mock()
                    );
            }
            dataObj.name1 = "First name";
            return dataObj;
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }

    [DataContract]
    public class MockSomethingData {
          [DataMember]
        public string Name {
            get;
            set;
        }
          [DataMember]
        public int Id { get; set; }
          [DataMember]
        public string OtherData { get; set; }

        private static Random roll;

        public static MockSomethingData Mock(){
            roll = (roll == null) ? new Random(10) : roll;
            int random = roll.Next(10000);
            return new MockSomethingData{
                Name = "the " + random.ToString(),
                Id = random,
                OtherData = Guid.NewGuid().ToString()
            };
        }
    }
}
